package com.uenpay.im.ui.old.activity.phonebook;

import com.qiyunxin.android.http.utils.StringUtils;
import com.qiyunxin.android.http.utils.Utils;
import com.qyx.android.utilities.DateUtils;
import com.uenpay.im.configuration.APIConfiguration;
import com.uenpay.im.entities.HttpInvokeResult;
import com.uenpay.im.invokeitems.BaseHttpInvokeItem;

import org.json.JSONException;
import org.json.JSONObject;

/**
 * @author SL
 * @created 2016-2-26 下午4:00:48
 * @copyRight http://www.qiyunxin.com
 * @function 邀请手机通讯用户
 */
public class InvitationContactsByPhoneBookInvokeItem extends BaseHttpInvokeItem {

	public class InvitationContactsByPhoneBookInvokeItemResult extends
			HttpInvokeResult {
	}

	public InvitationContactsByPhoneBookInvokeItemResult getOutPut() {
		return (InvitationContactsByPhoneBookInvokeItemResult) GetResultObject();
	}

	public InvitationContactsByPhoneBookInvokeItem(String username) {
		String time = DateUtils.getCurrentSeconds() + "";
		String sign = Utils.md5(Utils.md5(username + "_" + time));
		String url = APIConfiguration.getBaseUrl()
				+ "Cust/Cust/invitRegister?username="
				+ StringUtils.encodeParams(username) + "&time=" + time
				+ "&sign=" + sign + "&regtype=1&"
				+ APIConfiguration.getCustIdAndToken();
		SetUrl(url);
	}

	@Override
	protected Object DeserializeResult(String responseBody) {
		InvitationContactsByPhoneBookInvokeItemResult result = new InvitationContactsByPhoneBookInvokeItemResult();
		JSONObject json = null;
		try {
			json = new JSONObject(responseBody);
		} catch (JSONException e) {
			e.printStackTrace();
		}
		if (json == null) {
			return null;
		}
		result.status = json.optInt("status");
		result.msg = json.optString("msg");
		return result;
	}

}
